<?php

declare (strict_types=1);

namespace App\Model;

use App\Constants\ErrorCode;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\Relations\HasOne;
use Hyperf\Database\Model\SoftDeletes;

/**
 * @property int $id
 * @property string $industry_name
 * @property int $pid
 * @property string $tips
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property int $fileinfo_id
 * @property int $sort
 * @property int $level
 * @property string $deleted_at
 * @property int $create_by
 * @property int $update_by
 * @property int $delete_by
 * @property int $farm_produce
 * @property int $is_show
 */
class Industry extends CloudBase
{
    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_industry';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'string', 'pid' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'fileinfo_id' => 'integer', 'sort' => 'integer', 'level' => 'integer', 'create_by' => 'string', 'update_by' => 'string', 'delete_by' => 'string', 'farm_produce' => 'integer', 'is_show' => 'integer'];


    //    树形结构
    public function child()
    {
        return $this->hasMany(get_class($this), 'pid', 'id')
            ->orderBy('sort', 'desc')
            ->orderBy('id', 'desc');
    }

    public function children()
    {
        return $this->child()->with('children');
    }

    /**
     * 根据行业ID获取行业应缴纳保证金
     * @return HasOne
     */
    public function with_industry_cash()
    {
        return $this->hasOne(FlyCostSetInfo::class, 'industry_id', 'id');
    }

    /**
     * 获取虚拟产品参数
     * @return HasOne
     */
    public function with_virtual_params()
    {
        return $this->hasOne(FlyVirtualForm::class, 'industry_id', 'top_industry');
    }
}